package zb.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author wzby
 * @Date: 2022/8/6 11:03
 */
public class Stream6 {
    public static void main(String[] args) {
        List<Books> bok = new ArrayList<>(List.of(new Books("《java基础》", 12, 88), new Books("《java巩固》", 13, 128), new Books("《java进阶》", 12, 158), new Books("《java万能》", 21, 208)));
        Stream<Books> str = bok.stream();
        //bok.forEach(System.out::println);

        //IntStream is = str.mapToInt(e -> e.getId());
        //is.forEach(System.out::println);

        //Stream<String> str2 = str.map(e -> e.getName());
        //str2.forEach(System.out::println);

        //Stream<Books>转换List<Books>
        //List<Books> ml = str.collect(Collectors.toList());
        //Collectors.toList() 将流中的所有元素导出到一个列表( List )中
        //ml.add(new Books("《javase》",11,273));
        //for (Books b : ml){
            //System.out.println(b);
        //}

        //Set<String> set = str.map(Books::getName).collect(Collectors.toSet());
        //System.out.println(set);

        System.out.println(str.map(Books::getName).collect(Collectors.joining(",")));
    }
}
